/*
 * Copyright (C) 2021 The Chinese Software International Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package com.chinasoft.ohos.slice;

import com.chinasoft.ohos.ResourceTable;
import com.chinasoft.ohos.ability.*;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.utils.IntentConstants;
import ohos.utils.net.Uri;

/**
 * MainAbilitySlice
 *
 * @since 2021-03-29
 */
public class MainAbilitySlice extends AbilitySlice implements Component.ClickedListener {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        initViews();
    }

    private void initViews() {
        Button button0 = (Button) findComponentById(ResourceTable.Id_id_btn0);
        Button button1 = (Button) findComponentById(ResourceTable.Id_id_btn1);
        Button button2 = (Button) findComponentById(ResourceTable.Id_id_btn2);
        Button button3 = (Button) findComponentById(ResourceTable.Id_id_btn3);
        Button button4 = (Button) findComponentById(ResourceTable.Id_id_btn4);
        Button button5 = (Button) findComponentById(ResourceTable.Id_id_btn5);
        Button button6 = (Button) findComponentById(ResourceTable.Id_id_btn6);
        Button button7 = (Button) findComponentById(ResourceTable.Id_id_btn7);
        Button button8 = (Button) findComponentById(ResourceTable.Id_id_btn8);
        Button button9 = (Button) findComponentById(ResourceTable.Id_id_btn9);
        Button button10 = (Button) findComponentById(ResourceTable.Id_id_btn10);
        Button button11 = (Button) findComponentById(ResourceTable.Id_id_btn11);
        Button button12 = (Button) findComponentById(ResourceTable.Id_id_btn12);
        Button button13 = (Button) findComponentById(ResourceTable.Id_id_btn13);


        button0.setClickedListener(this);
        button1.setClickedListener(this);
        button2.setClickedListener(this);
        button3.setClickedListener(this);
        button4.setClickedListener(this);
        button5.setClickedListener(this);
        button6.setClickedListener(this);
        button7.setClickedListener(this);
        button8.setClickedListener(this);
        button9.setClickedListener(this);
        button10.setClickedListener(this);
        button11.setClickedListener(this);
        button12.setClickedListener(this);
        button13.setClickedListener(this);

    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    @Override
    public void onClick(Component component) {
        switch (component.getId()) {
            case ResourceTable.Id_id_btn0:
                nextPage(SimpleAbility.class);
                break;
            case ResourceTable.Id_id_btn1:
                nextPage(BaseFucAbility.class);
                break;
            case ResourceTable.Id_id_btn2:
                nextPage(AttrAbility.class);
                break;
            case ResourceTable.Id_id_btn3:
                nextPage(ColorPoolAbility.class);
                break;
            case ResourceTable.Id_id_btn4:
                nextPage(ItemStyleAbility.class);
                break;
            case ResourceTable.Id_id_btn5:
                nextPage(ElasticAbility.class);
                break;
            case ResourceTable.Id_id_btn6:
                nextPage(SlideAbility.class);
                break;
            case ResourceTable.Id_id_btn7:
                nextPage(DateAbility.class);
                break;
            case ResourceTable.Id_id_btn8:
                nextPage(NonViewAbility.class);
                break;
            case ResourceTable.Id_id_btn9:
                nextPage(ExtrasAbility.class);
                break;
            case ResourceTable.Id_id_btn10:
                nextPage(FlaglayoutAbility.class);
                break;
            case ResourceTable.Id_id_btn11:
                nextPage(DateDelayAbility.class);
                break;
            case ResourceTable.Id_id_btn12:
                nextPage(CustomWidthAbility.class);
                break;
            case ResourceTable.Id_id_btn13:
                nextPage(LocalConfigAbility.class);
                break;

            default:break;
        }
    }

    private void nextPage(Class pageName) {
        Intent secondIntent = new Intent();
        Operation operation = new Intent.OperationBuilder()
                .withDeviceId("")
                .withBundleName(this.getBundleName())
                .withAbilityName(pageName.getName())
                .build();
        secondIntent.setOperation(operation);
        startAbility(secondIntent);
    }



}
